<template>
    <div class="warp margin-bottom-20 flex">
        <div class="flex-1">
            <div class="strong padding-bottom-5">视频邀约</div>
            <div class="small padding-bottom-5">{{date}}</div>
            <div class="desc small">{{message.payload.description}}</div>
        </div>
        <div>
            <el-button type="text" v-if="isEnd">已结束</el-button>
            <el-button type="primary" @click="videoCall" v-else>查看</el-button>
        </div>
    </div>
</template>

<script>
    import {isToday, getDate, getTime, getFullDate, isBeforeDate} from '@/tim/date'
    import messageStoreMixin from "@/store/message/messageStoreMixin";
    import {decodeText} from "./decodeText";
    import defaultImage from '@/assets/images/avatar.png'
    import {createA} from "@/tim";
    import {appointment_type_message, appointment_type_message_china} from "@/tim/constact";

    export default {
        mixins: [messageStoreMixin],
        name: 'messageItem-item',
        props: ['message'],
        components: {},
        computed: {
            date() {
                return getFullDate(new Date(this.message.time * 1000))
            },
            contentList() {
                return this.message && this.message.payload && decodeText(this.message.payload)
            },
            from() {
                const isC2C = this.currentConversation.type === window.TIM.TYPES.CONV_C2C
                // 自己发送的用昵称渲染
                if (this.isMine) {
                    return this.currentUser.nick
                        || this.currentUser.userID
                        || this.currentUser.mobilePhone
                        || this.currentUser.id
                }
                // 1. C2C 的消息体中还无 nick / avatar 字段，需从 conversation.userProfile 中获取
                if (isC2C) {
                    return (
                        this.currentConversation.userProfile.nick ||
                        this.currentConversation.userProfile.userID ||
                        this.currentConversation.userProfile.mobilePhone
                    )
                } else if (this.currentConversation.type === window.TIM.TYPES.CONV_SYSTEM) {
                    return this.message.type === window.TIM.TYPES.MSG_GRP_SYS_NOTICE
                        ? '群系统通知'
                        : '系统通知'
                }
                // 2. 群组消息，用消息体中的 nick 渲染。nameCard暂时支持不完善
                return this.message.nick || this.message.from
            },
            date() {
                return getFullDate(new Date(this.message.time * 1000))
            },
            isEnd() {
                //三分钟之后就 显示结束了
                return isBeforeDate(moment(this.date).add('3', 'm'), new Date())
            },
            isMine() {
                // console.log(this.currentUserProfile, this.currentConversation);
                return this.message.flow === 'out'
            },
        },
        data() {
            return {
                appointment_type_message_china: appointment_type_message_china,
                appointment_type_message: appointment_type_message,
                popoverVisible: false,
                hasMessageAtMe: false,
                defaultImage: defaultImage
            }
        },
        mounted() {
        },
        methods: {
            //确定等待的预约
            appointment_wait() {
                createA(this.message.payload.data)
            },
            videoCall() {
                createA(this.message.payload.data)
            },
        }
    }
</script>

<style scoped>
    .warp {
        padding: 15px;
        background: rgba(246, 247, 250, 1);
        border-radius: 5px;
    }


</style>
